<?php


namespace app\common\model;


use app\common\lib\ZhyxMongo;
use catcher\exceptions\FailedException;

class DiseasePathBind extends BaseModel
{
    /**
     * 绑定用户随访路径
     * @param string $id 随访路径id
     * @param string $patientId 患者ID
     */
    public function bindDiseasePath($diseaseInfo, $patientInfo, $data, $sessionId = ''): array
    {
        $result = ZhyxMongo::getInstance()->setCollection('bind_disease_path')->insertOne([
            'patient_id' => $patientInfo["patientId"],
            'patient_name' => $patientInfo['name'] ?? "",
            'sex' => $patientInfo['sex'] ?? "",
            'age' => $patientInfo['inage'] ?? "",
            'telephone' => $patientInfo['presentTelphone'] ?? "",
            'disease_path_id' => $diseaseInfo["id"],
            'disease_name' => $diseaseInfo['name'],
            'step' => 0,
            'latest_status' => '0',
            'created_at' => time(),
            'doctors' => $data["doctors"],
            'deleted_at' => 0,
            'creator_id' => $data['creator_id'],
            'creator_name' => $data['creator_name'],
            'is_close' => 0
        ], ['session' => $sessionId]);
        if ($result->getInsertedCount() > 0) {
            return (new DiseaseTask())->writeTask($diseaseInfo, $patientInfo, $result->getInsertedId(), $data["doctors"], $sessionId);
        }
        throw new FailedException("绑定失败");
    }


}